﻿using System.Collections.Generic;
using System.Linq;

namespace Community.CsharpSqlite.WP.SqliteDataProvider.Base
{
    public class DataTable 
    {
        /// <summary>
        /// Gets or sets the name of the table.
        /// </summary>
        /// <value>The name of the table.</value>
        public string TableName { get; set; }

        /// <summary>
        /// Gets or sets the rows.
        /// </summary>
        /// <value>The rows.</value>
        public List<DataRow> Rows { get; set; }

        /// <summary>
        /// Gets or sets the columns.
        /// </summary>
        /// <value>The columns.</value>
        public List<DataColumn> Columns 
        { 
            get 
            {
                if (Rows.Count == 0)
                    return new List<DataColumn>();

                return Rows.First().GetColumns();
            }
        }

        /// <summary>
        /// Gets the name of the column offset.
        /// </summary>
        /// <param name="offset">The offset.</param>
        /// <returns></returns>
        public string GetName(int offset)
        {
            return Columns[offset].Name;
        }


        /// <summary>
        /// Gets the ordinal.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <returns></returns>
        public int GetOrdinal(string name)
        {
            if (Rows.Count == 0)
                return -1;

            return Rows.First().GetOrdinal(name);
        }
    }
}
